package com;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 罗俊华
 * @date 2021/7/23 - 3:31 下午
 */
public class MaxNumber {

    public static void main(String[] args) {
        int[] array = {3, 30, 34, 5, 9};
        String s = new MaxNumber().largestNumber(array);
        System.out.println(s);
    }

    public String largestNumber(int[] nums) {
        StringBuilder stringBuilder = new StringBuilder();
        Arrays.stream(nums).mapToObj(Integer::toString).sorted((String s1, String s2) -> {

            for (int i = 0; i < Math.min(s1.length(), s2.length()); i++) {
                char c1 = s1.charAt(i);
                char c2 = s2.charAt(i);
                if (c1 == c2) {
                    continue;
                }
                return c2 - c1;

            }

            return 0;
        }).forEachOrdered(stringBuilder::append);
        return stringBuilder.toString();
    }
}
